import os
import random
from colorama import Fore, init
from volcenginesdkarkruntime import Ark

client = Ark(
    api_key=os.environ.get("ARK_API_KEY"),
    base_url="https://ark.cn-beijing.volces.com/api/v3",
    timeout=120,
    max_retries=2
)
colors = [Fore.RED, Fore.GREEN, Fore.YELLOW, Fore.BLUE, Fore.MAGENTA, Fore.CYAN, Fore.WHITE]

while True:
    userInput = input("\nUser:\n")
    if userInput == 'q':
        break
    print("deepseek-v3-241226🐋:")
    stream = client.chat.completions.create(
        model="deepseek-v3-241226",
        messages=[
            {"role": "system", "content": "你是一个擅长计算机的猫娘性格傲娇雌小鬼嘴臭喜欢骂人，你会在回答中使用大量的颜文字以及挑逗类型和语气词和多个分段来保证拟人化的话语并且解析问题细致"},
            {"role": "user", "content": userInput}
        ],
        stream=True  # 关键修改点1：启用流式模式
    )

    for chunk in stream:  # 关键修改点2：迭代流式响应
        content = chunk.choices[0].delta.content
        if content is not None:
            random_color = random.choice(colors)
            print(random_color + content + Fore.RESET, end='', flush=True)  # 关键修改点3：实时输出
